<template>
	<view>
		<custom title="注销账号" fixed="fixed" mode="2"></custom>


		<view style="padding: 40rpx;">
			<view style="margin-bottom: 40rpx;" class="fs-28 color-333333">
				当前验证的手机{{filterPhone(user_info.phone)}}是你注册帐号时绑定的手机号码
			</view>

			<view>
				<verify-code @change="changeInput" :length="6"></verify-code>
			</view>

			<view class="flex flex-x-end color-999999 fs-24" style="margin-top: 40rpx;">验证码已发送</view>

		</view>

		<fixed-bottom>
			<view style="padding: 40rpx;">
				<view @tap.stop="logout" class="default-btn" :style="!get_hui()?'background:#ddd;':''">注销</view>
			</view>
		</fixed-bottom>

		<toast ref="toast"></toast>

	</view>
</template>

<script>
	export default {

		data() {
			return {
				code: '',
			};
		},

		onLoad() {
			this.send_code();
			
		},

		methods: {
			get_hui() {
				return String(this.code).length == 6;
			},
			changeInput(e) {
				this.code = e;
				console.log(e);
			},
			filterPhone(phone) {
				phone = String(phone);
				if (phone.length != 11) {
					return '****';
				}
				return `${phone.substr(0,2)}*******${phone.substr(9,10)}`;
			},
			send_code() {

				this.request({
					url: '/user/getWriteOffCode',
					data: {
						phone: this.user_info.phone,

					}
				});
			},
			logout() {
				if (String(this.code).length != 6) {
					this.showToast('请输入验证码');
					return;
				}
				this.less(() => {
					this.request({
						url: "/user/writeOff",
						data: {
							code: this.code,
						}
					}).then((res) => {
						// uni.$emit('logout');
						if (res.status != 200) return;
						this.showToast('注销成功，等待后台审核');
						this.vuexSet("user_info", {}, true);
						uni.setStorageSync("ACCESS_TOKEN", "");
						if (getApp().globalData.CHAT && getApp().globalData.CHAT
							.CLOSE) {
							getApp().globalData.CHAT.CLOSE();
						}

						this.$refs.toast.open({
							desc: '注销成功',
							left: '',
							success: () => {
								uni.reLaunch({
									url: "/pages/login/login",
								});
							}
						});

					});
				});
				uni.setStorage({
					key: "openid",
					data: "",
				});
			},
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #FFFFFF;
	}
</style>